package com.spukmk3me.math;

public class Rectanglef
{
public Rectanglef() {}
    
    public Rectanglef( float x, float y, float w, float h )
    {
        set( x, y, w, h );
    }
    
    public Rectanglef( Rectanglef rect )
    {
        copy( rect );
    }
    
    public void intersect( Rectanglef rect )
    {   
        float newX = Math.max( x, rect.x );
        float newY = Math.max( y, rect.y );
        
        w = Math.min( x + w - newX, rect.x + rect.w - newX );
        h = Math.min( y + h - newY, rect.y + rect.h - newY );
        x = newX;
        y = newY;
    }
    
    public boolean inRectangle( float x, float y )
    {
        return (x >= this.x) && (x < this.x + this.w) && (y >= this.y) && (y < this.y + this.h);
    }
    
    public void copy( Rectanglef rect )
    {
        x = rect.x;
        y = rect.y;
        w = rect.w;
        h = rect.h;
    }
    
    public void set( float x, float y, float w, float h )
    {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
    }
    
    public boolean isEquals( Rectanglef rect )
    {
        return (x == rect.x) && (y == rect.y) && (w == rect.w) && (h == rect.h);
    }
    
    public float x, y, w, h;
}
